package cn.wh.mybatis.binding;


import cn.wh.mybatis.session.SqlSession;

import java.lang.reflect.Proxy;

/**
 * @Description 映射器代理工厂
 * @Version 1.0.0
 * @Date 2022/11/29 15:38
 * @Created wh
 */
public class MapperProxyFactory<T>  {

    private final Class<T> mapperInterface;


    public MapperProxyFactory(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public T newInstance(SqlSession sqlSession){
        final MapperProxy<T> mapperProxy = new MapperProxy<>(sqlSession, mapperInterface);
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[]{mapperInterface}, mapperProxy);
    }

}
